Kwik.Page.include("Javascript.Prototype.String.js");
Kwik.Page.include("Kwik.Collections.Hashtable.js");

/** 
* The delimited string provides string to hashtable mapping
* @constructor
* @extends Kwik.Collections.Hashtable
* @requires Kwik.Collections.Hashtable
* @created 11:02 AM 5/12/2007
* @modified 11:44 PM 7/27/2009
*/
Kwik.Collections.DelimitedString = function(config)
{
	/** @ignore */
	Kwik.Utility.extend(this, "Kwik.Collections.Hashtable");
	this.__class.push("Kwik.Collections.DelimitedString");

	/** Delimiter string @type String */
	this.delimiter = ";";

	/** Assignment string @type String */
	this.assigner = "=";

	/** Loads the string into the collection, splitted by delimiter and assinger. The second boolean argument indicates whether keys should be appended on true else the collection is cleared. */
	this.fromString = function(value, append)
	{
		if(!append){this.removeAll();}
		if(!Kwik.Type.isString(value)){return;}
		var vals = value.split(this.delimiter);
		for(var i=0; i<vals.length; i++)
		{
			if(vals[i].indexOf(this.assigner)!=-1)
			{
				var key   = vals[i].substr(0, vals[i].indexOf(this.assigner));
				var value = vals[i].substr(vals[i].indexOf(this.assigner)+1);

				if(Kwik.Type.isString(key) && key.length>0)
				{
					this.add(key.trim(), value);
				}
			}
		}
	};
	
	/** Joins the values with assinger and delimiter @type String */
	this.toString = function()
	{
		var arr = [];
		for(e in this.items)
		{
			if(this.items[e] == Object.prototype[e]){continue;}
			arr.push(e  + this.assigner + this.item[e]);
		}
		return arr.join(this.delimiter);
	};

	/** Configure this object @type Kwik.Collection.DelimitedStringConfig */
	this.configure = function(config)
	{
		config = this.Kwik$Collections$Hashtable.configure(config);

		if(config.delimiter){this.delimiter = config.delimiter;}
		if(config.assigner){this.assigner = config.assigner;}
		if(config.value){this.fromString(config.value);}

		return config;
	};

	/** @ignore */
	this.main = function(config)
	{
		if(config){this.configure(config);}
	}; this.main(config);
};

/** 
* The delimited string configuration object
* @constructor
* @created 11:47 PM 7/27/2009
* @modified 11:47 PM 7/27/2009
*/
Kwik.Collections.DelimitedStringConfig = function()
{
	/** Delimiter char @type String */
	this.delimiter = "";
	/** Assigning char @type String */
	this.assigner = "";
	/** Delimited string value which will be loaded with the fromString method @type String */
	this.value = "";
};